<?php
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
$sqldeparment = mysql_query("SELECT dl.IDDepartment,dl.DepartmentName FROM department_lang dl WHERE dl.LangID='".$_SESSION['lang']."' ORDER BY dl.IDDepartment;");

?>
<script type="text/javascript">
	$(function() {
		$(".tree").treeview({
			collapsed: false,
			animated: "medium",
			control:"#sidetreecontrol",
			persist: "location"
		});
	})
	
	function onlickDept(iddept){
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {

		        document.getElementById("formdept").innerHTML=xmlhttp.responseText;
		        
		    }
		  }
		var lang = '<?=$_SESSION['lang']?>';
		xmlhttp.open("GET","admin/employeemanagement/process-onclick-dept.php?iddept="+iddept+"&newlang="+lang,true);
		xmlhttp.send();
	}

	function resetDept(){
		document.getElementById("deptname").value="";
		document.getElementById("locationdept").value="";
		document.getElementById("descriptiondept").value="";
	}
	function resetChildDept(){
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {

		        document.getElementById("formdept").innerHTML=xmlhttp.responseText;
		        
		    }
		  }
		var lang = '<?=$_SESSION['lang']?>';
		xmlhttp.open("GET","admin/employeemanagement/reset-child-dept.php?newlang="+lang,true);
		xmlhttp.send();
	}

	function registerDept(){
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {

		        document.getElementById("contentdept").innerHTML=xmlhttp.responseText;
		        
		    }
		  }
		var deptname = document.getElementById("deptname").value;
		var location = document.getElementById("locationdept").value;
		var description = document.getElementById("descriptiondept").value;
		var lang = '<?=$_SESSION['lang']?>';
		xmlhttp.open("GET","admin/employeemanagement/process-register-department.php?deptname="+deptname+"&location="+location+"&description="+description+"&newlang="+lang,true);
		xmlhttp.send();
	}

	function checkShowHide(theform){
		if($('#cenglish').is(':checked')){
			$('#tbEngland').show();
		}else{
			$('#tbEngland').hide();
		}

		if($('#cvietnam').is(':checked')){
			$('#tbVietnam').show();
		}else{
			$('#tbVietnam').hide();
		}

		if($('#ckorea').is(':checked')){
			$('#tbKorean').show();
		}else{
			$('#tbKorean').hide();
		}
	}

	function checkEmptyDept(){
		var deptname = document.getElementById("deptname").value;

		if(deptname.length==0){
			alert('<?=$l_alertdeptname?>');
			return false;
		}
	}
	
</script>

<script type="text/javascript">
$(document).ready(function(){
<?php 
if (isset($_SESSION['alertupdate'])){?>
	alert("<?php echo $l_capnhatthanhcong?>");
<?php unset($_SESSION['alertupdate']);}
?>

<?php 
if (isset($_SESSION['alertdelete'])){?>
alert("<?php echo $l_xoathanhcong?>");
<?php unset($_SESSION['alertdelete']);}
?>

<?php 
		if (isset($_SESSION['alertregister'])){?>
		alert("<?php echo $l_themthanhcong?>");
		<?php unset($_SESSION['alertregister']);}
		?>
		
});
</script>


<div id="contains" style="background-color: #edf4f7;">

	<div class="title"></div>
	<div class="content_code">
		<div style="width: 850px; padding: 30px 20px" id="contentdept">
			<div class="ldepart">
				<ul class="tree" style="background: none">
					<li class="roots"><span><?php echo $l_departments?></span>
						<ul style="background: none">
						<?php while($row=mysql_fetch_array($sqldeparment)){?>

							<li><span><a href="#"
									onclick="onlickDept('<?=$row[IDDepartment]?>');"
									id="<?=$row[IDDepartment]?>"><?php echo $row['DepartmentName']?>
								</a> </span></li>
								<?php }?>
						</ul>
					</li>
				</ul>
			</div>
			<div class="rdepart" id="formdept">
			<form action="admin/employeemanagement/result-register-dept.php" method="post" onsubmit="return checkEmptyDept();">
				<table border="0" cellpadding="0" cellspacing="5">
					<tr>
						<td width="150"> <?php echo $l_dept?> : <span style="color: red">*</span></td>
						<td><input type="text" class="indepart" id="deptname"
							name="deptname" value="" /></td>
					</tr>
					<tr>
						<td width="150"><span></span> <?php echo $l_location?> :</td>
						<td><input type="text" class="indepart" id="locationdept"
							name="locationdept" value="" /></td>
					</tr>
					<tr>
						<td width="150"><span></span> <?php echo $l_description?> :</td>
						<td><input type="text" class="indepart" id="descriptiondept"
							name="descriptiondept" value="" /></td>
					</tr>
				</table>
				<div style="width: 360px; margin-top: 20px; text-align: center">
					<input type="submit" value="<?php echo $l_register?>" class="btndepart" id="registerdept" name="registerdept"/> 
					<input type="submit" value="<?php echo $l_update?>" class="btndepartdisable" name="updatedept" id="updatedept"/> 
					<input type="button" value="<?php echo $l_reset?>" class="btndepart" onclick="resetDept();" id="resetdept" name="resetdept"/> 
					<input type="submit" value="<?php echo $l_delete?>" class="btndepartdisable" id="deletedept" name="deletedept"/>
				</div>
				</form>
			</div>
			<div style="clear: both"></div>
		</div>
	</div>
</div>
